package com.wxyzz.canteenadmin.order.afterSales.service.impl;

import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import com.wxyzz.canteenadmin.order.afterSales.mapper.AfterSalesMapper;
import com.wxyzz.canteenadmin.order.afterSales.param.AfterSaleParam;
import com.wxyzz.canteenadmin.order.afterSales.service.AfterSalesService;
import com.wxyzz.canteenadmin.order.afterSales.vo.AfterSalesVo;
import com.wxyzz.canteenadmin.order.afterSales.vo.MemberInfoVo;
import com.wxyzz.canteencommon.entity.ordermanager.AfterSale;
import com.wxyzz.canteencommon.exception.CustmerException;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.List;

@Service
public class AfterSalesServiceImpl implements AfterSalesService {

    @Resource
    private AfterSalesMapper afterSalesMapper;

    // 分页查询
    @Override
    public PageInfo<AfterSalesVo> getAfterSalesPageHelper(AfterSaleParam afterSaleParam) {
        PageHelper.startPage(afterSaleParam.getPageNum(),afterSaleParam.getPageSize());
        List<AfterSalesVo> afterSalesVos = afterSalesMapper.selectAfterSales(
                afterSaleParam.getAfterSaleId(), afterSaleParam.getMemberId(),
                afterSaleParam.getStartTime(), afterSaleParam.getEndTime(),
                afterSaleParam.getStatus() );
        PageInfo<AfterSalesVo> afterSalesVoPageInfo = new PageInfo<>(afterSalesVos);
        return afterSalesVoPageInfo;
    }

    // 审核售后订单
    @Override
    public void updateAfterSale(AfterSale afterSale) {
        int i = afterSalesMapper.updateAfterSales(afterSale);
        if (i == 0) {
            throw new CustmerException("修改失败");
        }
    }

    //通过订单号查询会员信息
    @Override
    public MemberInfoVo getMemberInfo(String orderNumber) {
        MemberInfoVo memberInfoVo = afterSalesMapper.selectMemberInfoByOrderNumber(orderNumber);
        if (memberInfoVo == null) {
            throw new CustmerException("会员信息不存在");
        }
        return memberInfoVo;
    }
}
